package com.example.administrator.puzzlepic;


import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.example.administrator.puzzlepic.com.xiaoxu.util.ScreenUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/4/7.
 */
public class PuzzleAdapter extends BaseAdapter {

    Context mContext;
    List <Bitmap> mBitmapItemLists;

    public PuzzleAdapter(Context mContext,List mBitmapItemLists){

        this.mContext = mContext;
        this.mBitmapItemLists = mBitmapItemLists;

    }

    @Override
    public int getCount() {
        return mBitmapItemLists.size();
    }

    //在此适配器中所代表的数据集中的条目数
    @Override
    public Object getItem(int position) {
        return mBitmapItemLists.get(position);
    }

    //获取数据集中与指定索引对应的数据项
    @Override
    public long getItemId(int position) {
        return position;
    }

    //每刷新一次条目时调用
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Bitmap bm = (Bitmap) getItem(position);

         ImageView mImage = null;

        if(convertView == null){
            mImage = new ImageView(mContext);

            // 设置布局 图片      要使用GridView.LayoutParams，否则会出现第一个item不显示的问题
            mImage.setLayoutParams(new GridView.LayoutParams(
                    mBitmapItemLists.get(position).getWidth(),
                    mBitmapItemLists.get(position).getHeight()));

            // 设置显示比例类型
           mImage.setScaleType(ImageView.ScaleType.FIT_CENTER);

        }else {

            mImage = (ImageView) convertView;

        }
        mImage.setImageBitmap(bm);

        return mImage;
    }

}


/*
*
*
* */




